home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / debug / fsdb / unassmbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-30  |  31.5 KB  |  1,296 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. /* Modified by Morten Welinder, terra@diku.dk, for use with full screen
  16.    debugger.  These changes are copyright 1994 by Morten Welinder.  */
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. #include "ed.h"
  22. #include "unassmbl.h"
  23. #include <debug/syms.h>
  24.  
  25. #define SOURCE_LIST
  26.  
  27. int seg_size=32;
  28.  
  29. static word8 buf[20];
  30. static word32 vaddr;
  31. static int bufp, bufe;
  32. static char ubuf[100], *ubufp;
  33. static col;
  34.  
  35. static void ua_str(char *s);
  36.  
  37. /* Percent tokens in strings:
  38.    First char after '%':
  39.         A - direct address
  40.         C - reg of r/m picks control register
  41.         D - reg of r/m picks debug register
  42.         E - r/m picks operand
  43.         F - flags register
  44.         G - reg of r/m picks general register
  45.         I - immediate data (takes extended size, data size)
  46.         J - relative IP offset
  47.         M - r/m picks memory
  48.         O - no r/m, offset only
  49.         R - mod of r/m picks register only
  50.         S - reg of r/m picks segment register
  51.         T - reg of r/m picks test register
  52.         X - DS:ESI
  53.         Y - ES:EDI
  54.         2 - prefix of two-byte opcode
  55.         e - put in 'e' if use32 (second char is part of reg name)
  56.             put in 'w' for use16 or 'd' for use32 (second char is 'w')
  57.         f - floating point (second char is esc value)
  58.         g - do r/m group 'n'
  59.         p - prefix
  60.         s - size override (second char is a,o)
  61.         + - make default signed
  62.    Second char after '%':
  63.         a - two words in memory (BOUND)
  64.         b - byte
  65.         c - byte or word
  66.         d - dword
  67.         p - 32 or 48 bit pointer
  68.         s - six byte pseudo-descriptor
  69.         v - word or dword
  70.         w - word
  71.         F - use floating regs in mod/rm
  72.         + - always sign
  73.         - - sign if negative
  74.         1-8 - group number, esc value, etc
  75. */
  76.  
  77. /* Known bugs (MW, Oct 1994):
  78.    - 486 instructions not included.
  79.    - Segment overrides with string instructions are not shown.
  80. */
  81.  
  82. char *opmap1[] = {
  83. /* 0 */
  84.   "add %Eb,%Gb", "add %Ev,%Gv", "add %Gb,%Eb", "add %Gv,%Ev",
  85.   "add al,%I-bb", "add %eax,%I-vv", "push es", "pop es",
  86.   "or %Eb,%Gb", "or %Ev,%Gv", "or %Gb,%Eb", "or %Gv,%Ev",
  87.   "or al,%Ibb", "or %eax,%Ivv", "push cs", "%2 ",
  88. /* 1 */
  89.   "adc %Eb,%Gb", "adc %Ev,%Gv", "adc %Gb,%Eb", "adc %Gv,%Ev",
  90.   "adc al,%I-bb", "adc %eax,%I-vv", "push ss", "pop ss",
  91.   "sbb %Eb,%Gb", "sbb %Ev,%Gv", "sbb %Gb,%Eb", "sbb %Gv,%Ev",
  92.   "sbb al,%I-bb", "sbb %eax,%I-vv", "push ds", "pop ds",
  93. /* 2 */
  94.   "and %Eb,%Gb", "and %Ev,%Gv", "and %Gb,%Eb", "and %Gv,%Ev",
  95.   "and al,%Ibb", "and %eax,%Ivv", "%pe", "daa",
  96.   "sub %Eb,%Gb", "sub %Ev,%Gv", "sub %Gb,%Eb", "sub %Gv,%Ev",
  97.   "sub al,%I-bb", "sub %eax,%I-vv", "%pc", "das",
  98. /* 3 */
  99.   "xor %Eb,%Gb", "xor %Ev,%Gv", "xor %Gb,%Eb", "xor %Gv,%Ev",
  100.   "xor al,%Ibb", "xor %eax,%Ivv", "%ps", "aaa",
  101.   "cmp %Eb,%Gb", "cmp %Ev,%Gv", "cmp %Gb,%Eb", "cmp %Gv,%Ev",
  102.   "cmp al,%I-bb", "cmp %eax,%I-vv", "%pd", "aas",
  103. /* 4 */
  104.   "inc %eax", "inc %ecx", "inc %edx", "inc %ebx",
  105.   "inc %esp", "inc %ebp", "inc %esi", "inc %edi",
  106.   "dec %eax", "dec %ecx", "dec %edx", "dec %ebx",
  107.   "dec %esp", "dec %ebp", "dec %esi", "dec %edi",
  108. /* 5 */
  109.   "push %eax", "push %ecx", "push %edx", "push %ebx",
  110.   "push %esp", "push %ebp", "push %esi", "push %edi",
  111.   "pop %eax", "pop %ecx", "pop %edx", "pop %ebx",
  112.   "pop %esp", "pop %ebp", "pop %esi", "pop %edi",
  113. /* 6 */
  114.   "pusha", "popa", "bound %Gv,%Ma", "arpl %Ew,%Rw",
  115.   "%pf", "%pg", "%so", "%sa",
  116.   "push %I-vv", "imul %Gv=%Ev*%I-vv", "push %I-vb", "imul %Gv=%Ev*%I-vb",
  117.   "insb %Yb,dx", "ins%ew %Yv,dx", "outsb dx,%Xb", "outs%ew dx,%Xv",
  118. /* 7 */
  119.   "jo %Jb", "jno %Jb", "jc %Jb",  "jnc %Jb",
  120.   "jz %Jb", "jnz %Jb", "jbe %Jb", "jnbe %Jb",
  121.   "js %Jb", "jns %Jb", "jpe %Jb", "jpo %Jb",
  122.   "jl %Jb", "jge %Jb", "jle %Jb", "jg %Jb",
  123. /* 8 */
  124.   "%g1 %Eb,%Ibb", "%g1 %Ev,%Ivv", 0, "%g1 %Ev,%Ivb",
  125.   "test %Eb,%Gb", "test %Ev,%Gv", "xchg %Eb,%Gb", "xchg %Ev,%Gv",
  126.   "mov %Eb,%Gb", "mov %Ev,%Gv", "mov %Gb,%Eb", "mov %Gv,%Ev",
  127.   "mov %Ew,%Sw", "lea %Gv,%M ", "mov %Sw,%Ew", "pop %Ev",
  128. /* 9 */
  129.   "nop", "xchg %eax,%ecx", "xchg %eax,%edx", "xchg %eax,%ebx",
  130.   "xchg %eax,%esp", "xchg %eax,%ebp", "xchg %eax,%esi", "xchg %eax,%edi",
  131.   "cbw", "cwd", "call %Ap", "fwait",
  132.   "push %eflags", "pop %eflags", "sahf", "lahf",
  133. /* a */
  134.   "mov al,%Ob", "mov %eax,%Ov", "mov %Ob,al", "mov %Ov,%eax",
  135.   "movsb %Xb,%Yb", "movs%ew %Xv,%Yv", "cmpsb %Xb,%Yb", "cmps%ew %Xv,%Yv",
  136.   "test al,%Ibb", "test %eax,%Ivv", "stosb %Yb,al", "stos%ew %Yv,%eax",
  137.   "lodsb al,%Xb", "lods%ew %eax,%Xv", "scasb al,%Xb", "scas%ew %eax,%Xv",
  138. /* b */
  139.   "mov al,%Ibb", "mov cl,%Ibb", "mov dl,%Ibb", "mov bl,%Ibb",
  140.   "mov ah,%Ibb", "mov ch,%Ibb", "mov dh,%Ibb", "mov bh,%Ibb",
  141.   "mov %eax,%I-vv", "mov %ecx,%I-vv", "mov %edx,%I-vv", "mov %ebx,%I-vv",
  142.   "mov %esp,%Ivv", "mov %ebp,%Ivv", "mov %esi,%I-vv", "mov %edi,%I-vv",
  143. /* c */
  144.   "%g2 %Eb,%Ibb", "%g2 %Ev,%Ibb", "ret %Iw", "ret",
  145.   "les %Gv,%Mp", "lds %Gv,%Mp", "mov %Eb,%Ibb", "mov %Ev,%I-vv",
  146.   "enter %Iww,%Ibb", "leave", "retf %Iww", "retf",
  147.   "int 3", "int %Ibb", "into", "iret",
  148. /* d */
  149.   "%g2 %Eb,1", "%g2 %Ev,1", "%g2 %Eb,cl", "%g2 %Ev,cl",
  150.   "aam %Ibb", "aad %Ibb", 0, "xlat",
  151.   "%f0", "%f1", "%f2", "%f3",
  152.   "%f4", "%f5", "%f6", "%f7",
  153. /* e */
  154.   "loopne %Jb", "loope %Jb", "loop %Jb", "jcxz %Jb",
  155.   "in al,%Ibb", "in %eax,%Ibb", "out %Ibb,al", "out %Ibb,%eax",
  156.   "call %Jv", "jmp %Jv", "jmp %Ap", "jmp %Jb",
  157.   "in al,dx", "in %eax,dx", "out dx,al", "out dx,%eax",
  158. /* f */
  159.   "lock %p ", 0, "repne %p ", "rep(e) %p ",
  160.   "hlt", "cmc", "%g3", "%g0",
  161.   "clc", "stc", "cli", "sti",
  162.   "cld", "std", "%g4", "%g5"
  163.   };
  164.  
  165. char *second[] = {
  166. /* 0 */
  167.   "%g6", "%g7", "lar %Gv,%Ew", "lsl %Gv,%Ew", 0, 0, "clts", 0,
  168.   0, 0, 0, 0, 0, 0, 0, 0,
  169. /* 1 */
  170.   0, 0, 0, 0, 0, 0, 0, 0,
  171.   0, 0, 0, 0, 0, 0, 0, 0,
  172. /* 2 */
  173.   "mov %Rd,%Cd", "mov %Rd,%Dd", "mov %Cd,%Rd", "mov %Dd,%Rd",
  174.   "mov %Rd,%Td", 0, "mov %Td,%Rd", 0,
  175.   0, 0, 0, 0, 0, 0, 0, 0,
  176. /* 3 */
  177.   0, 0, 0, 0, 0, 0, 0, 0,
  178.   0, 0, 0, 0, 0, 0, 0, 0,
  179.   0, 0, 0, 0, 0, 0, 0, 0,
  180.   0, 0, 0, 0, 0, 0, 0, 0,
  181.   0, 0, 0, 0, 0, 0, 0, 0,
  182.   0, 0, 0, 0, 0, 0, 0, 0,
  183.   0, 0, 0, 0, 0, 0, 0, 0,
  184.   0, 0, 0, 0, 0, 0, 0, 0,
  185.   0, 0, 0, 0, 0, 0, 0, 0,
  186.   0, 0, 0, 0, 0, 0, 0, 0,
  187. /* 8 */
  188.   "jo %Jv", "jno %Jv", "jc %Jv",  "jnc %Jv",
  189.   "jz %Jv", "jnz %Jv", "jbe %Jv", "jnbe %Jv",
  190.   "js %Jv", "jns %Jv", "jpe %Jv", "jpo %Jv",
  191.   "jl %Jv", "jge %Jv", "jle %Jv", "jg %Jv",
  192. /* 9 */
  193.   "seto %Eb", "setno %Eb", "setc %Eb",  "setnc %Eb",
  194.   "setz %Eb", "setnz %Eb", "setbe %Eb", "setnbe %Eb",
  195.   "sets %Eb", "setns %Eb", "setpe %Eb", "setpo %Eb",
  196.   "setl %Eb", "setge %Eb", "setle %Eb", "setg %Eb",
  197. /* a */
  198.   "push fs", "pop fs", 0, "bt %Ev,%Gv",
  199.   "shld %Ev,%Gv,%Ibb", "shld %Ev,%Gv,cl", 0, 0,
  200.   "push gs", "pop gs", 0, "bts %Ev,%Gv",
  201.   "shrd %Ev,%Gv,%Ibb", "shrd %Ev,%Gv,cl", 0, "imul %Gv,%Ev",
  202. /* b */
  203.   0, 0, "lss %Mp", "btr %Ev,%Gv",
  204.   "lfs %Mp", "lgs %Mp", "movzx %Gv,%Eb", "movzx %Gv,%Ew",
  205.   0, 0, "%g8 %Ev,%Ibb", "btc %Ev,%Gv",
  206.   "bsf %Gv,%Ev", "bsr %Gv,%Ev", "movsx %Gv,%Eb", "movsx %Gv,%Ew",
  207. /* c */
  208.   0, 0, 0, 0, 0, 0, 0, 0,
  209.   0, 0, 0, 0, 0, 0, 0, 0,
  210.   0, 0, 0, 0, 0, 0, 0, 0,
  211.   0, 0, 0, 0, 0, 0, 0, 0,
  212.   0, 0, 0, 0, 0, 0, 0, 0,
  213.   0, 0, 0, 0, 0, 0, 0, 0,
  214.   0, 0, 0, 0, 0, 0, 0, 0,
  215.   0, 0, 0, 0, 0, 0, 0, 0,
  216.   };
  217.  
  218. char *groups[][8] = {     /* group 0 is group 3 for %Ev set */
  219.   { "test %Ev,%Ivv", "test %Ev,%Ivv,", "not %Ev", "neg %Ev",
  220.     "mul %eax,%Ev", "imul %eax,%Ev", "div %eax,%Ev", "idiv %eax,%Ev" },
  221.   { "add%+-", "or", "adc%+-", "sbb%+-", "and", "sub%+-", "xor", "cmp%+-" },
  222.   { "rol", "ror", "rcl", "rcr", "shl", "shr", "shl", "sar" },
  223.   { "test %Eb,%Ibb", "test %Eb,%Ibb,", "not %Eb", "neg %Eb",
  224.     "mul al,%Eb", "imul al,%Eb", "div al,%Eb", "idiv al,%Eb" },
  225.   { "inc %Eb", "dec %Eb", 0, 0, 0, 0, 0, 0 },
  226.   { "inc %Ev", "dec %Ev", "call %Ev", "call %Ep",
  227.     "jmp %Ev", "jmp %Ep", "push %Ev", 0 },
  228.   { "sldt %Ew", "str %Ew", "lldt %Ew", "ltr %Ew",
  229.     "verr %Ew", "verw %Ew", 0, 0 },
  230.   { "sgdt %Ms", "sidt %Ms", "lgdt %Ms", "lidt %Ms",
  231.     "smsw %Ew", 0, "lmsw %Ew", 0 },
  232.   { 0, 0, 0, 0, "bt", "bts", "btr", "btc" }
  233.   };
  234.  
  235. /* zero here means invalid.  If first entry starts with '*', use st(i) */
  236. /* no assumed %EFs here.  Indexed by rm(modrm()) */
  237. char *f0[] = {0, 0, 0, 0, 0, 0, 0, 0};
  238. char *fop_9[]  = { "*fxch st,%GF" };
  239. char *fop_10[] = { "fnop", 0, 0, 0, 0, 0, 0, 0 };
  240. char *fop_12[] = { "fchs", "fabs", 0, 0, "ftst", "fxam", 0, 0 };
  241. char *fop_13[] = { "fld1", "fldl2t", "fldl2e", "fldpi",
  242.                    "fldlg2", "fldln2", "fldz", 0 };
  243. char *fop_14[] = { "f2xm1", "fyl2x", "fptan", "fpatan",
  244.                    "fxtract", "fprem1", "fdecstp", "fincstp" };
  245. char *fop_15[] = { "fprem", "fyl2xp1", "fsqrt", "fsincos",
  246.                    "frndint", "fscale", "fsin", "fcos" };
  247. char *fop_21[] = { 0, "fucompp", 0, 0, 0, 0, 0, 0 };
  248. char *fop_28[] = { 0, 0, "fclex", "finit", 0, 0, 0, 0 };
  249. char *fop_32[] = { "*fadd %GF,st" };
  250. char *fop_33[] = { "*fmul %GF,st" };
  251. char *fop_36[] = { "*fsubr %GF,st" };
  252. char *fop_37[] = { "*fsub %GF,st" };
  253. char *fop_38[] = { "*fdivr %GF,st" };
  254. char *fop_39[] = { "*fdiv %GF,st" };
  255. char *fop_40[] = { "*ffree %GF" };
  256. char *fop_42[] = { "*fst %GF" };
  257. char *fop_43[] = { "*fstp %GF" };
  258. char *fop_44[] = { "*fucom %GF" };
  259. char *fop_45[] = { "*fucomp %GF" };
  260. char *fop_48[] = { "*faddp %GF,st" };
  261. char *fop_49[] = { "*fmulp %GF,st" };
  262. char *fop_51[] = { 0, "fcompp", 0, 0, 0, 0, 0, 0 };
  263. char *fop_52[] = { "*fsubrp %GF,st" };
  264. char *fop_53[] = { "*fsubp %GF,st" };
  265. char *fop_54[] = { "*fdivrp %GF,st" };
  266. char *fop_55[] = { "*fdivp %GF,st" };
  267. char *fop_60[] = { "fstsw ax", 0, 0, 0, 0, 0, 0, 0 };
  268.  
  269. char **fspecial[] = { /* 0=use st(i), 1=undefined 0 in fop_* means undefined */
  270.   0, 0, 0, 0, 0, 0, 0, 0,
  271.   0, fop_9, fop_10, 0, fop_12, fop_13, fop_14, fop_15,
  272.   f0, f0, f0, f0, f0, fop_21, f0, f0,
  273.   f0, f0, f0, f0, fop_28, f0, f0, f0,
  274.   fop_32, fop_33, f0, f0, fop_36, fop_37, fop_38, fop_39,
  275.   fop_40, f0, fop_42, fop_43, fop_44, fop_45, f0, f0,
  276.   fop_48, fop_49, f0, fop_51, fop_52, fop_53, fop_54, fop_55,
  277.   f0, f0, f0, f0, fop_60, f0, f0, f0,
  278.   };
  279.  
  280. char *floatops[] = { /* assumed " %EF" at end of each.  mod != 3 only */
  281. /*00*/ "fadd", "fmul", "fcom", "fcomp",
  282.        "fsub", "fsubr", "fdiv", "fdivr",
  283. /*08*/ "fld", 0, "fst", "fstp",
  284.        "fldenv", "fldcw", "fstenv", "fstcw",
  285. /*16*/ "fiadd", "fimul", "ficomw", "ficompw",
  286.        "fisub", "fisubr", "fidiv", "fidivr",
  287. /*24*/ "fild", 0, "fist", "fistp",
  288.        "frstor", "fldt", 0, "fstpt",
  289. /*32*/ "faddq", "fmulq", "fcomq", "fcompq",
  290.        "fsubq", "fsubrq", "fdivq", "fdivrq",
  291. /*40*/ "fldq", 0, "fstq", "fstpq",
  292.        0, 0, "fsave", "fstsww",
  293. /*48*/ "fiaddw", "fimulw", "ficomw", "ficompw",
  294.        "fisubw", "fisubrw", "fidivw", "fidivr",
  295. /*56*/ "fildw", 0, "fistw", "fistpw",
  296.        "fbldt", "fildq", "fbstpt", "fistpq"
  297.   };
  298.  
  299. static word8 getbyte(void)
  300. {
  301.   int s;
  302.   if (bufp >= bufe)
  303.   {
  304.     s = 20;
  305.     if ((vaddr & 0xfff) + s > 0x1000)
  306.       s = 0x1000 - (vaddr & 0xfff);
  307.     read_child(vaddr, buf, s);
  308.     bufe = s;
  309.     bufp = 0;
  310.   }
  311.   vaddr++;
  312. #ifndef FULLSCR
  313.   printf("%02x", buf[bufp]);
  314.   col+=2;
  315. #endif
  316.   return buf[bufp++];
  317. }
  318.  
  319. static int default_pick_sign;
  320.  
  321. static prefix;
  322. static modrmv;
  323. static sibv;
  324. static opsize;
  325. static addrsize;
  326.  
  327. static int
  328. modrm(void)
  329. {
  330.   if (modrmv == -1)
  331.     modrmv = getbyte();
  332.   return modrmv;
  333. }
  334.  
  335. static int
  336. sib(void)
  337. {
  338.   if (sibv == -1)
  339.     sibv = getbyte();
  340.   return sibv;
  341. }
  342.  
  343. #define mod(a)  (((a)>>6)&7)
  344. #define reg(a)  (((a)>>3)&7)
  345. #define rm(a)   ((a)&7)
  346. #define ss(a)   (((a)>>6)&7)
  347. #define indx(a) (((a)>>3)&7)
  348. #define base(a) ((a)&7)
  349.  
  350. /*------------------------------------------------------------------------*/
  351. void
  352. uprintf(char *s, ...)
  353. {
  354.   char **a = &s;
  355.   vsprintf(ubufp, s, a+1);
  356.   while (*ubufp) ubufp++;
  357. }
  358.  
  359. void
  360. uputchar(char c)
  361. {
  362.   if (c == '\t')
  363.   {
  364.     do {
  365.       *ubufp++ = ' ';
  366.     } while ((ubufp-ubuf) % 8);
  367.   }
  368.   else
  369.     *ubufp++ = c;
  370.   *ubufp = 0;
  371. }
  372.  
  373. /*------------------------------------------------------------------------*/
  374. int bytes(char c)
  375. {
  376.   switch (c)
  377.   {
  378.     case 'b':
  379.       return 1;
  380.     case 'w':
  381.       return 2;
  382.     case 'd':
  383.       return 4;
  384.     case 'v':
  385.       if (opsize == 32)
  386.         return 4;
  387.       else
  388.         return 2;
  389.   }
  390.   return 0;
  391. }
  392.  
  393. /*------------------------------------------------------------------------*/
  394. static void
  395. ohex(char c, int extend, int optional, int defsize, int sign)
  396. {
  397.   static char *formats[4] = { "%#x", "%d", "%+d", "%+d" };
  398.   char *fmt;
  399.   int n=0, s=0, i;
  400.   int32 delta;
  401.   unsigned char buf[6];
  402.   char *name;
  403.   fmt = formats[sign];
  404.  
  405.   switch (c)
  406.   {
  407.     case 'a':
  408.       break;
  409.     case 'b':
  410.       n = 1;
  411.       break;
  412.     case 'w':
  413.       n = 2;
  414.       break;
  415.     case 'd':
  416.       n = 4;
  417.       break;
  418.     case 's':
  419.       n = 6;
  420.       break;
  421.     case 'c':
  422.     case 'v':
  423.       if (defsize == 32)
  424.         n = 4;
  425.       else
  426.         n = 2;
  427.       break;
  428.     case 'p':
  429.       if (defsize == 32)
  430.         n = 6;
  431.       else
  432.         n = 4;
  433.       s = 1;
  434.       break;
  435.     case 'x':
  436.       return;
  437.   }
  438.   for (i=0; i<n; i++)
  439.     buf[i] = getbyte();
  440.   for (; i<extend; i++)
  441.     buf[i] = (buf[i-1] & 0x80) ? 0xff : 0;
  442.   if (s)
  443.   {
  444.     uprintf("0x%02x%02x:", buf[n-1], buf[n-2]);
  445.     n -= 2;
  446.   }
  447.   switch (n)
  448.   {
  449.     case 1:
  450.       delta = *(signed char *)buf;
  451.       break;
  452.    case 2:
  453.       delta = *(signed short *)buf;
  454.       break;
  455.     case 4:
  456.       delta = *(signed long *)buf;
  457.       break;
  458.   }
  459.   if (extend > n)
  460.   {
  461.     if (delta || !optional)
  462.     {
  463.       uprintf(fmt, delta);
  464.     }
  465.     return;
  466.   }
  467.   if ((n == 4) && sign < 2)
  468.   {
  469. #ifdef FULLSCR
  470.     if (delta >= 0 && delta < 0x1000) /* No labels there, only constants.  */
  471.       name = 0;
  472.     else
  473. #endif
  474.     name = syms_val2name(delta, &delta);
  475.     if (name)
  476.     {
  477.       uprintf("%s", name);
  478.       if (delta)
  479.         uprintf("+%lu", delta);
  480.       return;
  481.     }
  482.   }
  483.   switch (n)
  484.   {
  485.     case 1:
  486.       uprintf(fmt, (unsigned char)delta);
  487.       break;
  488.     case 2:
  489.       uprintf(fmt, (unsigned short)delta);
  490.       break;
  491.     case 4:
  492.       uprintf(fmt, (unsigned long)delta);
  493.       break;
  494.   }
  495. }
  496.  
  497. /*------------------------------------------------------------------------*/
  498.  
  499. static char *reg_names[3][8]={
  500.   { "al","cl","dl","bl","ah","ch","dh","bh" },
  501.   { "ax","cx","dx","bx","sp","bp","si","di" },
  502.   { "eax","ecx","edx","ebx","esp","ebp","esi","edi" }};
  503.  
  504. void
  505. reg_name(int which, char size)
  506. {
  507.   if (size == 'F')
  508.   {
  509.     uprintf("st(%d)", which);
  510.     return;
  511.   }
  512.   if (((size == 'v') && (opsize == 32)) || (size == 'd'))
  513.   {
  514.     uputchar('e');
  515.   }
  516.   if (size == 'b')
  517.   {
  518.     uputchar("acdbacdb"[which]);
  519.     uputchar("llllhhhh"[which]);
  520.   }
  521.   else
  522.   {
  523.     uputchar("acdbsbsd"[which]);
  524.     uputchar("xxxxppii"[which]);
  525.   }
  526. }
  527.  
  528. /*------------------------------------------------------------------------*/
  529. int
  530. do_sib (int m)
  531. {
  532.   static char *i_str[] = {
  533.     "+eax", "+ecx", "+edx", "+ebx", "", "+ebp", "+esi", "+edi" };
  534.   int pick_signed = default_pick_sign;
  535.   int s, i, b, extra=0;
  536.   s = ss(sib());
  537.   i = indx(sib());
  538.   b = base(sib());
  539.   if (b == 5)
  540.   {
  541.       if (m == 0)
  542.       {
  543.         ua_str("%p:[");
  544.         ohex('d', 4, 0, addrsize, 1);
  545.       }
  546.       else
  547.       {
  548.         ua_str("%p:[ebp");
  549.         pick_signed |= 2;
  550.       }
  551.   }
  552.   else
  553.   {
  554.     static char *sib_str[] = {
  555.       "%p:[eax", "%p:[ecx", "%p:[edx", "%p:[ebx", "%p:[esp", 0, "%p:[esi", "%p:[edi" };
  556.     pick_signed |= 2;
  557.     ua_str(sib_str[b]);
  558.     if ((b == i) && (b != 4) && (i != 5))
  559.       extra = 1;
  560.   }
  561.   if (extra == 0)
  562.   {
  563.     pick_signed |= 2;
  564.     uprintf(i_str[i]);
  565.   }
  566.   if (i != 4 && s)
  567.     uprintf("*%d", (1<<s)+extra);
  568.   return pick_signed;
  569. }
  570.  
  571. /*------------------------------------------------------------------------*/
  572.  
  573. static int modrm_extend;
  574.  
  575. void
  576. do_modrm(char t)
  577. {
  578.   int m = mod(modrm());
  579.   int r = rm(modrm());
  580.   int extend = (addrsize == 32) ? 4 : 2;
  581.   int pick_signed = default_pick_sign;
  582.   if (m == 3)
  583.   {
  584.     reg_name(r, t);
  585.     return;
  586.   }
  587.   if ((m == 0) && (r == 5) && (addrsize == 32))
  588.   {
  589.     ua_str("%p:[");
  590.     ohex('d', extend, 0, addrsize, 0);
  591.     uputchar(']');
  592.     return;
  593.   }
  594.   if ((m == 0) && (r == 6) && (addrsize == 16))
  595.   {
  596.     ua_str("%p:[");
  597.     ohex('w', extend, 0, addrsize, 0);
  598.     uputchar(']');
  599.     return;
  600.   }
  601.   if ((addrsize != 32) || (r != 4))
  602.     ua_str("%p:[");
  603.   if (addrsize == 16)
  604.   {
  605.     static char *r_str[] = {
  606.       "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx" };
  607.     uprintf(r_str[r]);
  608.     pick_signed |= 2;
  609.   }
  610.   else
  611.   {
  612.     if (r == 4)
  613.       pick_signed |= do_sib(m);
  614.     else
  615.     {
  616.       uprintf(reg_names[2][r]);
  617.       pick_signed |= 2;
  618.     }
  619.   }
  620.   modrm_extend = extend;
  621.   ohex("xbv"[m], extend, 1, addrsize, pick_signed);
  622.   uputchar(']');
  623. }
  624.  
  625. /*------------------------------------------------------------------------*/
  626. static void
  627. floating_point(int e1)
  628. {
  629.   int esc = e1*8 + reg(modrm());
  630.   if (mod(modrm()) == 3)
  631.   {
  632.     if (fspecial[esc])
  633.     {
  634.       if (fspecial[esc][0] && (fspecial[esc][0][0] == '*'))
  635.       {
  636.         ua_str(fspecial[esc][0]+1);
  637.       }
  638.       else
  639.       {
  640.         ua_str(fspecial[esc][rm(modrm())]);
  641.       }
  642.     }
  643.     else
  644.     {
  645.       ua_str(floatops[esc]);
  646.       ua_str(" %EF");
  647.     }
  648.   }
  649.   else
  650.   {
  651.     ua_str(floatops[esc]);
  652.     ua_str(" %EF");
  653.   }
  654. }
  655.  
  656. /*------------------------------------------------------------------------*/
  657. static void
  658. percent(char c, char **tptr)
  659. {
  660.   word32 vofs, delta;
  661.   char *name;
  662.   int default_signed = default_pick_sign;
  663.   char t = *(*tptr)++, it;
  664.   int extend = (addrsize == 32) ? 4 : 2;
  665.   int iextend;
  666.  
  667.   if (c != '+')
  668.   {
  669.     if (t == '-')
  670.     {
  671.       default_signed = 1;
  672.       t = *(*tptr)++;
  673.     }
  674.     else if (t == '+')
  675.     {
  676.       default_signed = 2;
  677.       t = *(*tptr)++;
  678.     }
  679.   }
  680.   switch (c)
  681.   {
  682.     case 'A':
  683.       ohex(t, extend, 0, addrsize, 0);
  684.       break;
  685.     case 'C':
  686.       uprintf("cr%d", reg(modrm()));
  687.       break;
  688.     case 'D':
  689.       uprintf("dr%d", reg(modrm()));
  690.       break;
  691.     case 'E':
  692.       do_modrm(t);
  693.       break;
  694.     case 'G':
  695.       if (t == 'F')
  696.         reg_name(rm(modrm()), t);
  697.       else
  698.         reg_name(reg(modrm()), t);
  699.       break;
  700.     case 'I':
  701.       it = *(*tptr)++;
  702.       switch (t)
  703.       {
  704.         case 'b':
  705.           iextend = 1;
  706.           break;
  707.         case 'v':
  708.           iextend = extend;
  709.           break;
  710.         default:
  711.           iextend = 0;
  712.           break;
  713.       }
  714.       ohex(it, iextend, 0, opsize, default_signed);
  715.       break;
  716.     case 'J':
  717.       vofs = 0;
  718.       switch (bytes(t))
  719.       {
  720.         case 1:
  721.           vofs = (int8)getbyte();
  722.           break;
  723.         case 2:
  724.           vofs = getbyte();
  725.           vofs += getbyte()<<8;
  726.           vofs = (int16)vofs;
  727.           break;
  728.         case 4:
  729.           vofs = (word32)getbyte();
  730.           vofs |= (word32)getbyte() << 8;
  731.           vofs |= (word32)getbyte() << 16;
  732.           vofs |= (word32)getbyte() << 24;
  733.           break;
  734.       }
  735.       name = syms_val2name(vofs+vaddr, &delta);
  736.       uprintf("%s", name);
  737.       if (delta)
  738.         uprintf("+%lu (0x%lx %c)", delta, vofs+vaddr,
  739.                 (vofs & 0x80000000L) ? 0x1e : 0x1f);
  740.       break;
  741.     case 'M':
  742.       do_modrm(t);
  743.       break;
  744.     case 'O':
  745.       ua_str("%p:[");
  746.       ohex(t, extend, 0, addrsize, 0);
  747.       uputchar(']');
  748.       break;
  749.     case 'R':
  750.       do_modrm(t);
  751.       break;
  752.     case 'S':
  753.       uputchar("ecsdfg"[reg(modrm())]);
  754.       uputchar('s');
  755.       break;
  756.     case 'T':
  757.       uprintf("tr%d", reg(modrm()));
  758.       break;
  759.     case 'X':
  760.       uprintf("ds:[");
  761.       if (addrsize == 32)
  762.         uputchar('e');
  763.       uprintf("si]");
  764.       break;
  765.     case 'Y':
  766.       uprintf("es:[");
  767.       if (addrsize == 32)
  768.         uputchar('e');
  769.       uprintf("di]");
  770.       break;
  771.     case '2':
  772.       ua_str(second[getbyte()]);
  773.       break;
  774.     case 'e':
  775.       if (opsize == 32)
  776.       {
  777.         if (t == 'w')
  778.           uputchar('d');
  779.         else
  780.         {
  781.           uputchar('e');
  782.           uputchar(t);
  783.         }
  784.       }
  785.       else
  786.         uputchar(t);
  787.       break;
  788.     case 'f':
  789.       floating_point(t-'0');
  790.       break;
  791.     case 'g':
  792.       ua_str(groups[t-'0'][reg(modrm())]);
  793.       break;
  794.     case 'p':
  795.       switch (t)
  796.       {
  797.         case 'c':
  798.         case 'd':
  799.         case 'e':
  800.         case 'f':
  801.         case 'g':
  802.         case 's':
  803.           prefix = t;
  804.           ua_str(opmap1[getbyte()]);
  805.           break;
  806.         case ':':
  807.           if (prefix)
  808.             uprintf("%cs:", prefix);
  809.           break;
  810.         case ' ':
  811.           ua_str(opmap1[getbyte()]);
  812.           break;
  813.       }
  814.       break;
  815.     case 's':
  816.       switch (t)
  817.       {
  818.         case 'a':
  819.           addrsize = 48 - addrsize;
  820.           ua_str(opmap1[getbyte()]);
  821.           break;
  822.         case 'o':
  823.           opsize = 48 - opsize;
  824.           ua_str(opmap1[getbyte()]);
  825.           break;
  826.       }
  827.       break;
  828.     case '+':
  829.       switch (t)
  830.       {
  831.         case '-':
  832.           default_pick_sign = 1;
  833.           break;
  834.         case '+':
  835.           default_pick_sign = 2;
  836.           break;
  837.         default:
  838.           default_pick_sign = 0;
  839.           break;
  840.       }
  841.   }
  842. }
  843.  
  844. static void
  845. ua_str(char *s)
  846. {
  847.   int c;
  848.   if (s == 0)
  849.   {
  850.     uprintf("<invalid>");
  851.     return;
  852.   }
  853.   while ((c = *s++) != 0)
  854.   {
  855.     if (c == '%')
  856.     {
  857.       c = *s++;
  858.       percent(c, &s);
  859.     }
  860.     else
  861.       if (c == ' ')
  862.         uputchar('\t');
  863.       else
  864.         uputchar(c);
  865.   }
  866. }
  867.  
  868. #ifdef SOURCE_LIST
  869. /*
  870. ** A little brute force hacking and hey presto! A source debugger!
  871. ** Courtesy of Kent Williams williams@herky.cs.uiowa.edu
  872. **
  873. ** KNOWN BUGS:
  874. ** The program will summarily terminate if you run out
  875. ** of memory while you're looking for all the line offsets.  Since
  876. ** a two thousand line source file only creats an 8K array, and the
  877. ** symbol table goes into virtual memory, this shouldn't happen too
  878. ** often.
  879. **
  880. ** One file is left open for reading indefinitely.
  881. */
  882. #include <stdlib.h>
  883. #include <string.h>
  884. /*
  885. ** keep the source line offsets in virtual memory, so you can
  886. ** debug big programs
  887. */
  888. extern word32 salloc(word32 size);
  889. #define symsput(where,ptr,size)     memput(where,ptr,size)
  890. #define symsget(where,ptr,size)     memget(where,ptr,size)
  891.  
  892. /*
  893. ** for each file encountered, keep an array of line start offsets
  894. ** so you can seek into the file to display the current line.
  895. */
  896. typedef struct {
  897.         char *filename;
  898.         long *offsets;
  899.     int line_count;
  900. } line_info;
  901.  
  902. static line_info *files;
  903. static last_file = 0;
  904.  
  905. /*
  906. ** cache_fopen -- cache the most recently accessed source file
  907. ** so you aren't constantly reopening a new file
  908. */
  909. static FILE *
  910. myfopen1 (char *name)
  911. {
  912.   static char fname[80] = "";
  913.   static FILE *current = NULL;
  914.   char temp[80];
  915.  
  916.   _fixpath (name, temp);
  917.  
  918.   if (current != NULL && strcmp (fname,temp) == 0)
  919.     return current;
  920.   if (current != NULL)
  921.     fclose(current);
  922.   strcpy (fname,temp);
  923.   current = fopen (temp,"rb");
  924.   return current;
  925. }
  926.  
  927. FILE *
  928. cache_fopen(char *name)
  929. {
  930.   FILE *f;
  931.   char *s, *t, u[80];
  932.   int l;
  933.  
  934.   f = myfopen1 (name);
  935. #ifdef FULLSCR
  936.   s = source_path;
  937.  
  938.   while (f == NULL && s && *s)
  939.     {
  940.       t = index (s, ';');
  941.       l = t ? t - u - 1 : strlen (s);
  942.       strncpy (u, s, l);
  943.       if (l > 0 && u[l - 1] != '/' && u[l - 1] != '\\')
  944.     u[l++] = '/';
  945.       u[l] = 0;
  946.       strcat (u, name);
  947.       f = myfopen1 (u);
  948.       s = t;
  949.     }
  950. #endif
  951.   return f;
  952. }
  953.  
  954. /*
  955. ** add_file -- add a file to the source line database
  956. */
  957. static int
  958. add_file(char *name) {
  959.         FILE *f = cache_fopen(name);
  960.         char c;
  961.         long *lines,curpos;
  962.         unsigned curline = 0;
  963.  
  964.         if(!f)
  965.                 return -1;
  966.  
  967.         if (files == 0)
  968.           files = (line_info *)malloc(sizeof(line_info));
  969.         else
  970.           files = realloc(files, (last_file+1) * sizeof(line_info));
  971.  
  972.         files[last_file].filename = strdup(name);
  973.  
  974.         /*
  975.         ** build an array of line offsets in real memory.
  976.         */
  977.         lines = malloc(sizeof(long));
  978.         lines[curline++] = curpos = 0L;
  979.  
  980.         while((c = getc(f)) != EOF) {
  981.                 curpos++;
  982.                 if(c == '\n') {
  983.                         lines = realloc(lines,sizeof(long)*(curline+1));
  984.                         lines[curline++] = curpos;
  985.                 }
  986.         }
  987.         /*
  988.         ** now move the whole array into virtual memory
  989.         */
  990.         files[last_file].offsets = lines;
  991.         files[last_file].line_count = curline;
  992.  
  993.         last_file++;
  994.         return 0;
  995. }
  996.  
  997. static line_info *
  998. find_file(char *name) {
  999.         int i;
  1000.         for(i = 0; i < last_file; i++)
  1001.                 if(strcmp(name,files[i].filename) == 0)
  1002.                         return &files[i];
  1003.         if(add_file(name) == -1)
  1004.                         return NULL;
  1005.         return find_file(name);
  1006. }
  1007.  
  1008.  
  1009. int
  1010. file_line_count (char *file)
  1011. {
  1012.   line_info *li = find_file (file);
  1013.  
  1014.   if (li)
  1015.     return li->line_count;
  1016.   else
  1017.     return 0;
  1018. }
  1019.  
  1020. /*
  1021. ** put_source_line -- print the current source line, along with
  1022. ** the line # and file name, if necessary.
  1023. */
  1024. #ifdef FULLSCR
  1025. void put_source_line(int fmt, char *name, int line, char *result)
  1026. #else
  1027. void put_source_line(int fmt,char *name,int line)
  1028. #endif
  1029. {
  1030.         line_info *current = find_file(name);
  1031.         FILE *cur;
  1032. #ifdef FULLSCR
  1033.     /* See below */
  1034.     char *sbuf, *chp;
  1035. #endif
  1036.         if(current == NULL) {
  1037.         regular:
  1038. #ifdef FULLSCR
  1039.       sbuf = alloca (strlen (name) + 10);
  1040.       switch (fmt)
  1041.         {
  1042.         case 0:
  1043.           sprintf (sbuf, " (%s#%d):", name, line);
  1044.           break;
  1045.         case 1:
  1046.           sprintf (sbuf, "#%d:", line);
  1047.           break;
  1048.         case 2:
  1049.           sprintf (sbuf, "%4d: ", line);
  1050.           break;
  1051.         }
  1052.       strcat (result, sbuf);
  1053. #else
  1054.           if(fmt == 0)
  1055.                   printf(" (%s#%d):\n", name, line);
  1056.           else
  1057.                   printf("#%d:\n", line);
  1058. #endif
  1059.         } else {
  1060. #ifdef FULLSCR
  1061.             /* I really hate set a maximum like this, but setting it
  1062.            this high will hopefully not feel like a maximum.  */
  1063.                 char buf[1000];
  1064. #else
  1065.                 char buf[70];
  1066. #endif
  1067.                 long offset;
  1068.                 if((cur = cache_fopen(name)) == NULL)
  1069.                         goto regular;
  1070.                 /*
  1071.                 ** get the symbol out of virtual memory
  1072.                 */
  1073.                 offset = current->offsets[line-1];
  1074.                 fseek(cur,offset,0);
  1075.                 /*
  1076.                 ** truncate line so it fits on screen.
  1077.                 */
  1078.                 fgets(buf,sizeof(buf)-2,cur);
  1079. #ifdef FULLSCR
  1080.                 if ((chp = strchr (buf, '\n')))
  1081.           if (chp != buf && chp[-1] == '\r')
  1082.             chp [-1] = '\0';
  1083.           else
  1084.             *chp = '\0';
  1085.         sbuf = alloca (sizeof (buf) + 100);
  1086.         switch (fmt)
  1087.           {
  1088.           case 0:
  1089.             sprintf (sbuf, " (%s#%d): %s", name, line, buf);
  1090.             break;
  1091.           case 1:
  1092.             sprintf (sbuf, "#%d: %s", line, buf);
  1093.             break;
  1094.           case 2:
  1095.             sprintf (sbuf, "%4d: %s", line, buf);
  1096.             break;
  1097.           }
  1098.         strcat (result, sbuf);
  1099. #else
  1100.                 if(strchr(buf,'\n') == NULL)
  1101.                         strcat(buf,"\n");
  1102.                 if(fmt == 0)
  1103.                         printf(" (%s#%d): %s", name, line,buf);
  1104.                 else
  1105.                         printf("#%d: %s",line,buf);
  1106. #endif
  1107.         }
  1108. }
  1109.  
  1110. #endif
  1111.  
  1112. int last_unassemble_unconditional;
  1113. int last_unassemble_jump;
  1114. int last_unassemble_extra_lines;
  1115. /* Please read the above regarding this max.  */
  1116. char last_unassemble_text[1100];
  1117.  
  1118. char *
  1119. unassemble_proper (word32 v, int *len)
  1120. {
  1121.   prefix = 0;
  1122.   modrmv = sibv = -1;
  1123.   opsize = addrsize = seg_size;
  1124.   vaddr = v;
  1125.   bufp = bufe = 0;
  1126.   col = 0;
  1127.   ubufp = ubuf;
  1128.   ua_str(opmap1[getbyte()]);
  1129.  
  1130.   *len = vaddr - v;
  1131.   return ubuf;
  1132. }
  1133.  
  1134. char *
  1135. unassemble_source (word32 v)
  1136. {
  1137.   word32 delta;
  1138.   char *name, *lname, *result = last_unassemble_text;
  1139.   int linenum;
  1140.  
  1141.   result[0] = '\0';
  1142.  
  1143.   name = syms_val2name (v, &delta);
  1144.   if (!delta && (name[0] != '0'))
  1145.     {
  1146.       strcat (strcat (result, name), "()");
  1147.       lname = syms_val2line (v, &linenum, 1);
  1148.       if (lname)
  1149.     put_source_line (0, lname, linenum, result);
  1150.       else
  1151.     strcat (result, ":");
  1152.     }
  1153.   else
  1154.     {
  1155.       lname = syms_val2line (v, &linenum, 1);
  1156.       if (lname)
  1157.     put_source_line (1, lname, linenum, result);
  1158.       else
  1159.     return NULL;
  1160.     }
  1161.   return result;
  1162. }
  1163.  
  1164. #ifndef FULLSCR
  1165. word32 unassemble(word32 v, int showregs)
  1166. {
  1167.   int a,b,n,wi, linenum;
  1168.   char *cmp, *brp;
  1169.   word8 *wp;
  1170.   word32 delta;
  1171.   char *name, *lname;
  1172.   char *regpos;
  1173.  
  1174.   default_pick_sign = 0;
  1175.   ansi(A_yellow);
  1176.   last_unassemble_unconditional = 0;
  1177.   last_unassemble_jump = 0;
  1178.   last_unassemble_extra_lines = 0;
  1179.   name = syms_val2name(v, &delta);
  1180.   if (!delta && (name[0] != '0'))
  1181.   {
  1182.     printf("%s()", name);
  1183.     lname = syms_val2line(v, &linenum, 1);
  1184.     if (lname)
  1185. #ifndef SOURCE_LIST
  1186.       printf(" (%s#%d):\n", lname, linenum);
  1187. #else
  1188.       put_source_line(0,lname,linenum);
  1189. #endif
  1190.     else
  1191.       printf(":\n");
  1192.     last_unassemble_extra_lines++;
  1193.   }
  1194.   else
  1195.   {
  1196.     lname = syms_val2line(v, &linenum, 1);
  1197.     if (lname)
  1198.     {
  1199. #ifndef SOURCE_LIST
  1200.       printf("#%d:\n", linenum);
  1201. #else
  1202.       put_source_line(1,lname,linenum);
  1203. #endif
  1204.       last_unassemble_extra_lines++;
  1205.     }
  1206.   }
  1207.  
  1208.   ansi(A_grey);
  1209.   printf("%08lx: ", v);
  1210. #if 0
  1211.   if (!page_is_valid(v+ARENA) || !page_is_valid(v+5+ARENA))
  1212.   {
  1213.     printf("<bad address>\n");
  1214.     return v;
  1215.   }
  1216. #endif
  1217.  
  1218.   prefix = 0;
  1219.   modrmv = sibv = -1;
  1220.   opsize = addrsize = seg_size;
  1221.   vaddr = v;
  1222.   bufp = bufe = 0;
  1223.   col = 0;
  1224.   ubufp = ubuf;
  1225.   ua_str(opmap1[getbyte()]);
  1226.   do {
  1227.     putchar(' ');
  1228.     col++;
  1229.   } while (col < 15);
  1230.   col += strlen(ubuf);
  1231.   do {
  1232.     uputchar(' ');
  1233.     col++;
  1234.   } while (col < 43);
  1235.  
  1236.   ansi(A_cyan);
  1237.   printf("%s", ubuf);
  1238.   ansi(A_grey);
  1239.  
  1240.   if ((strncmp(ubuf, "jmp ", 4) == 0)
  1241.      || (strncmp(ubuf, "ret", 3) == 0))
  1242.     last_unassemble_unconditional = 1;
  1243.   if (ubuf[0] == 'j')
  1244.     last_unassemble_jump = 1;
  1245.  
  1246.   if (!showregs)
  1247.   {
  1248.     putchar('\n');
  1249.     return vaddr;
  1250.   }
  1251.  
  1252.   col -= 43; /* total 25 columns left */
  1253.   wp = (word8 *)&(a_tss.tss_eax);
  1254.   cmp = strchr(ubuf+8, ',');
  1255.   brp = strchr(ubuf+8, '[');
  1256.   if (!cmp) cmp = ubuf+8;
  1257.   if (!brp) brp = ubufp;
  1258.   if (brp < cmp) cmp = brp;
  1259.   if (strncmp(ubuf, "mov ", 4))
  1260.     cmp = ubuf+8;
  1261.   for (b=0; b<8; b++)
  1262.   {
  1263.     for (a=2; a>=0; a--)
  1264.     {
  1265.       n = (a==0) ? 1 : ((a==1) ? 2 : 4);
  1266.       if (regpos = strstr(cmp, reg_names[a][b]))
  1267.       {
  1268.     if (!isalnum (regpos[-1]) && (regpos[-1] != '_'))
  1269.     {
  1270.       col += strlen(reg_names[a][b])+n*2+2;
  1271.       if (col > 29)
  1272.       {
  1273.         printf("\n%53s", "");
  1274.         col = 0;
  1275.       }
  1276.       printf("%s=", reg_names[a][b]);
  1277.       if (a == 0)
  1278.         wi = (b&3)*4 + (b>>2);
  1279.       else
  1280.         wi = b*4;
  1281.       while (n)
  1282.       {
  1283.         n--;
  1284.         printf("%02x", wp[wi+n]);
  1285.       }
  1286.       putchar(' ');
  1287.       break;
  1288.     }
  1289.       }
  1290.     }
  1291.   }
  1292.   putchar('\n');
  1293.   return vaddr;
  1294. }
  1295. #endif /* not FULLSCR */
  1296.